public class Demo5 {
    public static void main(String[] args) {
        Thread t =new Thread(()->{
            while(!Thread.currentThread().isInterrupted()){//Thread.currentThread().isInterrupted() 默认是false
                //括号内   true是线程要终止了     false线程要继续执行
                System.out.println("thread");
                try{
                    Thread.sleep(1000);
                }catch (InterruptedException e){
                    //e.printStackTrace();
                    throw new RuntimeException(e);//e.printStackTrace();-->会继续执行
                }
            }
    });
        t.start();
        try{
            Thread.sleep(3000);
        }catch (InterruptedException e){
            throw new RuntimeException(e);
        }
        t.interrupt();//通过这个方法,相当于设置Boolean值为true-->还能唤醒sleep等阻塞的方法
        //抛出异常,不会等待
    }
}
